package com.controller;

import com.domain.Resource;
import com.domain.ResourceVO;
import com.domain.ResponseResult;
import com.github.pagehelper.PageInfo;
import com.service.ResourceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/resource")
public class ResourceController {

    @Autowired
    private ResourceService resourceService;
    /*
     * 资源分页及多条件查询
     * */
    @RequestMapping("/findAllResource")
    public ResponseResult findAllResource(@RequestBody ResourceVO resourceVO){
        PageInfo<Resource> pageInfo = resourceService.findAllResource(resourceVO);
        return new ResponseResult(true,200,"分页&&多条件查询成功",pageInfo);

    }
    /*
     * 添加及更新资源
     * */
    @RequestMapping("/saveOrUpdateResource")
    public ResponseResult saveOrUpdateResource(@RequestBody Resource resource){
        if (resource.getId() == null){
            resourceService.saveResource(resource);
            return new ResponseResult(true,200,"添加资源成功",null);
        }else {
            resourceService.updateResource(resource);
            return new ResponseResult(true,200,"更新资源成功",null);
        }
    }
    /*
     * 删除资源
     * */
    @RequestMapping("/deleteResource")
    public ResponseResult deleteResource(Integer id){
        resourceService.deleteResource(id);
        return new ResponseResult(true,200,"删除资源成功",null);
    }
}
